
var resId="";

function LoadGuest(Tabs)
{
	var Tabsguest = Tabs.guest;
	$("[name=show_list_guests]").remove();
	if(Tabsguest == null) return;
	for(var i=Tabsguest.length-1; i >= 0 ;i--){
		var isnull =(Tabsguest[i] == null);
		var id=(isnull)?"-":Tabsguest[i]['id'];
		var gid=(isnull)?"0":Tabsguest[i]['id'];
		var sname=(!isnull&&Tabsguest[i]['SName']!=null)?Tabsguest[i]['SName']:"";
		var name=(isnull)?"-":Tabsguest[i]['Name'];
		var tel=(isnull)?"-":Tabsguest[i]['phone'];
		var mail=(isnull)?"-":Tabsguest[i]['mail'];

		var tableData = "<tr bgcolor=\"#ECECD9\" name=\"show_list_guests\">"+
			"<td style=\"border-right:dotted #CCC 1px; height:24px; text-align:left;\">"+
				"<input type=\"checkbox\" name=\"guestname_id_ckb\" style=\"margin-right:4px\" id=\""+gid+"\">p<span id=\"guestname_guestid_"+id+"\" >"+id+"</span>"+
			"</td>"+
			"<td style=\" border-right:dotted #CCC 1px;\" align=\"center\">"+
				"<span style=\" color:#647AE1;\" id=\"guestname_guestname"+id+"\">"+sname+" "+name+"</span>"+
			"</td>"+
			"<td style=\" border-right:dotted #CCC 1px;\">"+
				"<span id=\"guestname_guestphone"+id+"\">"+tel+"</span>"+
			"</td>"+
			"<td colspan=\"6\" style=\" border-right:dotted #CCC 1px;\"  align=\"center\">"+
				"<span id=\"guestname_guestemail"+id+"\" >"+mail+"</span>"+
			"</td>"+
			"<td colspan=\"6\" style=\" border-right:dotted #CCC 1px;\" align=\"center\">Guest Type</span></td>"+
			"<td colspan=\"6\" style=\" border-right:dotted #CCC 1px;\">&nbsp;</td>"+
			"</tr>";
		$("#add_insert_guest").after(tableData);
	}
}

function InsertGuest() {
	if($('[id=add_insert_guest]:visible').size()!=0){
			$('[id=add_insert_guest]').children().find('input[type=text]').val("");
			$('[id=add_insert_guest]:visible').hide();
			return;
	}
	var Tabs = getCurrentTabData();
	Tabs.showAddguest = true;
	$("#add_insert_guest").replaceWith(
	"<tr bgcolor=\"#666\" id=\"add_insert_guest\">"+
	"<td style=\"border-right:dotted #CCC 1px;\" height=\"24px\"><div style=\"float:left;\">&nbsp;</div></td>"+
	"<td style=\"border-right:dotted #CCC 1px;\">"+
		"<span name=\"insert_solutation\" style=\"margin-right:5px;\"><select id=\"insert_solutation\"  style=\"height:20px; width:22%\" ></select></span>"+
		"<span style=\"pending-right:4px;\"><input id=\"insert_name\" type=\"text\" placeholder=\"Name\" style=\"width:35%; margin-right:5px;\" onblur=\"saveGuestinput()\"></span>"+
		"<span><input id=\"insert_lastname\" type=\"text\" placeholder=\"Lastname\" style=\"width:35%;\" onblur=\"saveGuestinput()\"></span>"+
	"</td>"+
	"<td style=\" border-right:dotted #CCC 1px;\" >"+
		"<input id=\"insert_guestname_phone\" type=\"text\" style=\"width:100%;\" onblur=\"saveGuestinput()\">"+
	"</td>"+
	"<td colspan=\"6\" style=\" border-right:dotted #CCC 1px;\" align=\"center\">"+
		"<input id=\"insert_guestname_email\" type=\"text\" style=\"width:100%;\" onblur=\"saveGuestinput()\">"+
	"</td>"+
	"<td colspan=\"6\" style=\" border-right:dotted #CCC 1px;\"  align=\"center\">"+
		"<select id=\"insert_guestname_type\"  style=\"height:20px; width:100%\" onblur=\"saveGuestinput()\" >" +
				"<option value=\"adult\">Adult</option>" +
				"<option value=\"children\">Child</option>" +
		"</select>"+
	"</td>"+
	"<td colspan=\"6\" style=\" border-right:dotted #CCC 1px;\">"+
		"<div><input type=\"button\" value=\"Add\" style=\"border:solid #ccc 1px; \" onclick=\"AddGuest()\"></div>"+
	"</td>"+
	"</tr>");
	loadSalutation();
	
}

function saveGuestinput(){
	var Tabs = getCurrentTabData();
	var obj = {};
	obj.salutation = $("#insert_solutation").attr("value");
	obj.name = $("#insert_name").attr("value");
	obj.lastName =$("#insert_lastname").attr("value");
	obj.phone =$("#insert_guestname_phone").attr("value");
	obj.mail = $("#insert_guestname_email").attr("value");
	Tabs.showAddguestData=obj;
}
function loadSalutation()
{
	var opts = SharedData.Salutation.length;
	if($("#insert_solutation > option").length == 0)
		for(var i=0; i<opts; i++)
			$("#insert_solutation").append( $("<option>").val(SharedData.Salutation[i].id).html(SharedData.Salutation[i].title));
}

function AddGuest()
{
	if($('[id=add_insert_guest]:visible').children().find('input[type=text][id=insert_name]:visible').val()=="" ||
			$('[id=add_insert_guest]:visible').children().find('input[type=text][id=insert_guestname_phone]:visible').val()==""){
		$('[id=add_insert_guest]').children().find('input[type=text]').val("");
		$('[id=add_insert_guest]:visible').hide();
		simpleDialog("Add guest unsuccessful please fill name and telephonep number.");
		return;
	}
	var obj = {};
	var resId =getCurrentTabData().resId;
	obj.salutation = $("#insert_solutation").attr("value");
	obj.name = $("#insert_name").attr("value");
	obj.lastName =$("#insert_lastname").attr("value");
	obj.phone =$("#insert_guestname_phone").attr("value");
	obj.mail = $("#insert_guestname_email").attr("value");
	var link = "/reservationService?func=insertGuest&resId="+resId+"&salutationId="+obj.salutation+"&name="+obj.name+"&lastName="+obj.lastName+"&phone="+obj.phone+"&mail="+obj.mail;
	simpleserviceWithArgs(link,null,saveGuestSuccess,obj);
}

function saveGuestSuccess(data,obj){
	var objArray = JSON.parse(data);
	var checkLogOut = CheckSession(objArray);
	if(checkLogOut)
		return;
	if(objArray  == null){
		var msgDialog = $("#EmptyMessageDialog");
		msgDialog.dialog({
			height : 115,
			resizable : false,
			title: simpleLabel_Message,
			close: function() { cancelClearRender(null); }
		});
		msgDialog.html('<div style="padding: 5px 0 0 5px;">'+saveFail_label+'</div>' +
				'<div style="padding:20px 10px 0 0; float:right;">' +
				'<span><button style="float:right" class="btn" onclick="destroyLocalDialog(this,cancelClearRender);">' + simpleLabel_Button_OK + '</button></span>' +
			'</div>');
	}
	else
	{
		$("#add_insert_guest").css("display","none");
		$("#add_insert_guest").replaceWith(
				"<tr id=\"add_insert_guest\" style=\"display:none;\">"+
				"<td colspan=\"6\">"+
				"&nbsp;"+
				"</td>"+
				"</tr>"
		);
		var Tabs = getCurrentTabData();
		if(Tabs.guest !=null){Tabs.guest.push(JSON.parse(data));}else{Tabs.guest=[];Tabs.guest.push(JSON.parse(data));}
		LoadGuest(Tabs);
		getCurrentTabData().ResData.adult+=1;
		delete Tabs.showAddguest;
		delete Tabs.showAddguestData;
	}
}

function DeleteGuest() {
	if(res == 0){
		$('input[name=guestname_id_ckb]:checked').parent().parent().parent().remove();
	}else{
		var StringArray = [];
		var resId =getCurrentTabData().resId;
		$("input[name=guestname_id_ckb]:visible:checked").each(function() {
			StringArray.push($(this).attr("id"));
		});
		
		if(StringArray.length == 0)
			simpleDialog("can't delete!!");
		else{
			var link = "/reservationService?func=removeGuestFormRes&resId="+resId+"&guestIdString="+StringArray;
			simpleserviceWithArgs(link,null,DeleteGuestSuccess,StringArray);
		}
	}
}

function DeleteGuestSuccess(data,StringArray){
	
	var objArray = JSON.parse(data);
	var checkLogOut = checkSessionAdmin(objArray);
	if(checkLogOut)
		return;
	if(objArray == null)
		simpleDialog(saveFail_label);
	else
	{
		var Tabs =getCurrentTabData();
		for(var i=0;i<StringArray.length;i++){
			if(Tabs.Owner.id == StringArray[i]){
				Tabs.Owner = null;
				fillOwnerInfo(Tabs);
				fillOwner(Tabs);
				break;
			}
		}
		var link ="/reservationService?func=loadGuestList&resId="+Tabs.resId;
		simpleserviceWithArgs(link,null,loadnewGuest_success,Tabs);
	}
}

function loadnewGuest_success(data,Tabs)
{
	Tabs.guest = JSON.parse(data);
	LoadGuest(Tabs);
}

function ShowManageGuestDialog()
{
		var buttons = [
			{title:btn_managegueat_cancel,style:"", callback: function(thisdialog,args){
				thisdialog.dialog("close");
			}},
			{ title:btn_managegueat_save,style:"", callback: function(thisdialog,args){
				AddEditGuestManage();
				thisdialog.dialog("close");
			}}
		];
		var msgDialog = customDialog(managegueat,$('[name=manage_guest_dialog]').html(),{ width: 990},buttons,null);
		fillDropdown($("[name=manage_guest_salutation]"),SharedData.Salutation,"id","title");
		var Array  = JSON.parse('[{"genderValue":"M","genText":"male"},{"genderValue":"F","genText":"female"}]');
		fillDropdown($("[name=manage_guest_gender]"),Array,"genderValue","genText");
		loadnationalityDropDown($("[name=manage_guest_nationality]"));
		dateselectDroupDown($('[name=manage_guest_dateborn_date]'));
		monthselectDropdown($('[name=manage_guest_dateborn_month]'));
		yearselectDropdown($('[name=manage_guest_dateborn_year]'));
		
		print_manageguest_country($('[id*=manage_guest_company_country]:last'));
		print_manageguest_country($("[id*=manage_guest_country]:last"));
		var t1 = $("[id*=manage_guest_company_country]:last").val();
		var t2 = $("[id*=manage_guest_country]:last").val();
		print_state_bydom($("[id*=manage_guest_province]"),t2);
		print_state_bydom($("[id*=manage_guest_company_province]"),t1);
		fillmanageGuestsData();
}

function loadnationalityDropDown(dom)
{
	var states = ["Afghan","Albanian","Algerian", "American","Andorran","Angolan","Antiguans",
			"Argentinean", "Armenian", "Australian","Austrian","Azerbaijani","Bahamian", "Bahraini","Bangladeshi",
			"Barbadian", "Barbudans", "Batswana", "Belarusian","Belgian","Belizean","Beninese","Bhutanese", "Bolivian","Bosnian",
			"Brazilian", "British", "Bruneian", "Bulgarian", "Burkinabe","Burmese", "Burundian","Cambodian","Cameroonian",
			"Canadian", "Cape Verdean", "Central African", "Chadian", "Chilean","Chinese", "Colombian", "Comoran", "Congolese",
			"Costa Rican","Croatian", "Cuban","Cypriot","Czech", "Danish", "Djibouti", "Dominican", "Dutch","East Timorese","Ecuadorean",
			"Egyptian", "Emirian","Equatorial Guinean","Eritrean","Estonian", "Ethiopian", "Fijian","Filipino","Finnish",
			"French", "Gabonese", "Gambian","Georgian","German","Ghanaian","Greek","Grenadian", "Guatemalan", "Guinea-Bissauan",
			"Guinean","Guyanese","Haitian","Herzegovinian","Honduran","Hungarian", "I-Kiribati","Icelander", "Indian", "Indonesian",
			"Iranian","Iraqi","Irish","Israeli","Italian","Ivorian","Jamaican","Japanese","Jordanian","Kazakhstani","Kenyan",
			"Kittian and Nevisian", "Kuwaiti","Kyrgyz","Laotian", "Latvian", "Lebanese","Liberian","Libyan", "Liechtensteiner",
			"Lithuanian","Luxembourger","Macedonian", "Malagasy","Malawian","Malaysian","Maldivan", "Malian", "Maltese","Marshallese",
			"Mauritanian","Mauritian","Mexican", "Micronesian","Moldovan", "Monacan","Mongolian","Moroccan","Mosotho","Motswana","Mozambican",
			"Namibian","Nauruan","Nepalese","New Zealander","Nicaraguan","Nigerian","Nigerien","North Korean","Northern Irish",
			"Norwegian","Omani","Pakistani","Palauan","Panamanian","Papua New Guinean","Paraguayan", "Peruvian","Polish",
			"Portuguese","Qatari", "Romanian","Russian","Rwandan","Saint Lucian","Salvadoran", "Samoan", "San Marinese","Sao Tomean",
			"Saudi","Scottish","Senegalese","Serbian","Seychellois", "Sierra Leonean", "Singaporean","Slovakian","Slovenian",
			"Solomon Islander","Somali","South African","South Korean","Spanish","Sri Lankan","Sudanese","Surinamer","Swazi","Swedish",
			"Swiss","Syrian","Taiwanese","Tajik","Tanzanian","Thai","Togolese","Tongan","Trinidadian or Tobagonian","Tunisian",
			"Turkish","Tuvaluan","Ugandan","Ukrainian","Uruguayan","Uzbekistani","Venezuelan","Vietnamese","Welsh","Yemenite",
			"Zambian","Zimbabwean"];
	dom.prepend(optionString.format("-",simpleLabel_Select));
	for(var hi=0; hi<states.length; hi++) 
dom.append("<option value=\""+states[hi]+"\">"+states[hi]+"</option>");
}
function dateselectDroupDown(dom)
{
	for(var i=1; i<=31; i++) {
		dom.append("<option value=\""+i+"\">"+i+"</option>");
	}	
}
function monthselectDropdown(dom)
{
	var month = [Month_Short_Jan,Month_Short_Feb,Month_Short_Mar,
			Month_Short_Apr,Month_Short_May,Month_Short_Jun,
			Month_Short_Jul,Month_Short_Aug,Month_Short_Sep,
			Month_Short_Oct,Month_Short_Nov,Month_Short_Dec
		];
	for(var hi=0; hi<month.length; hi++) 
dom.append("<option value=\""+(hi+1)+"\">"+month[hi]+"</option>");
}

function yearselectDropdown(dom)
{
	var date = new Date();
	date.getFullYear();
	for(var hi=1930; hi<=date.getFullYear(); hi++) 
dom.append("<option value=\""+hi+"\">"+(hi+543)+"</option>");
}

function chooseCountry(dom)
{
	if($(dom).attr("id") == "manage_guest_company_country")
	{
		var t1 = $("[id*=manage_guest_company_country]:last").val();
		print_state_bydom($("[id*=manage_guest_company_province]"),t1);
	}
	if($(dom).attr("id")== "manage_guest_country")
	{
		var t2 = $("[id*=manage_guest_country]:last").val();
		print_state_bydom($("[id*=manage_guest_province]"),t2);
		
	}
}
function fillmanageGuestsData()
{
	var Tabs = getCurrentTabData();
	var Sname="-";
	var name=(Tabs.Owner!=null)?Tabs.Owner.firstName:"";
	var lastname=(Tabs.Owner!=null)?Tabs.Owner.lastName:"";
	var gender="-";
	var nationality="-";
	var date="1";
	var month="1";
	var year="1930";
	var idcard="";
	var passport="";
	var driverlicense="";
	var socialsnumber="";
	var address="";
	var city="";
	var country="";
	var province="";
	var zipcode="";
	var tel=(Tabs.Owner!=null)?Tabs.Owner.phone:"";
	var fax="";
	var email="";
	
	var companyname="";
	var companyaddress="";
	var companycity="";
	var companycountry="";
	var companyprovince="";
	var companyzipcode="";
	var companytel="";
	var companyfax="";
	var companyemail="";
	
	var guestnote="";
	var markvip=false;
	if(Tabs.resId != 0)
	{ 
		var guest = Tabs.Owner;
		if(guest == null){return;}
		Sname=guest.salutationString;
		name =guest.firstName;
		lastname=guest.lastName;
		(guest.gender=="")?gender="-":gender=guest.gender;
		var dateborn =new Date(guest.birthday).toFormatString("yyyy-MM-dd");
		date = dateborn.split("-")[2];
		month = dateborn.split("-")[1];
		year = dateborn.split("-")[0];
		(guest.nationalityString!= null)?nationality=guest.nationalityString:nationality ="-";
		($.isNumeric(guest.idNumber))?idcard=guest.idNumber:idcard="";
		($.isNumeric(guest.idNumber))?passport=guest.passportNumber:passport="";
		($.isNumeric(guest.idNumber))?driverlicense=guest.driverlicense:driverlicense="";
		($.isNumeric(guest.socialSecuritycard))?socialsnumber=guest.socialSecuritycard:socialsnumber="";
		address=guest.addressLine1;
		city=guest.city;
		(guest.country!=null)?country=guest.country:country=0;
		(guest.state!=null)?province=guest.state:province=0;
		zipcode=guest.pincode;
		tel=guest.phone;
		fax=guest.fax;
		email=guest.mail;
		companyname=guest.company;
		companyaddress=guest.officeAddress;
		companycity=guest.officeCity;
		companycountry=guest.officeCountry;
		companyprovince=guest.officeState;
		companyzipcode=guest.officePincode;
		companytel=guest.officePhone1;
		companyfax=guest.officeFax;
		companyemail=guest.officeEmail;
		guestnote=guest.note;
		(guest.isVIP!=null)?markvip=guest.isVIP:markvip=false;
	}

	$("[name=manage_guest_salutation]").find('option[value='+Sname+']').attr('selected','selected');
	$("[name=manage_guest_name]:visible").val(name);
	$("[name=manage_guest_lastname]:visible").val(lastname);
	$("[name=manage_guest_gender]:visible").find('option[value="'+gender+'"]').attr("selected","selected")
	$("[name=manage_guest_nationality]:visible").find('option[value='+nationality+']').attr('selected','selected');
	$("[name=manage_guest_dateborn_date]:visible").find('option[value='+date+']').attr('selected','selected');
	$("[name=manage_guest_dateborn_month]:visible").find('option[value='+month+']').attr('selected','selected');
	$("[name=manage_guest_dateborn_year]:visible").find('option[value='+year+']').attr('selected','selected');
	$("[name=manage_guest_idcard]:visible").val(idcard);
	$("[name=manage_guest_passport]:visible").val(passport);
	$("[name=manage_guest_driverlicense]:visible").val(driverlicense);
	$("[name=manage_guest_socialsnumber]:visible").val(socialsnumber);
	$("[name=manage_guest_address]:visible").val(address);
	$("[name=manage_guest_city]:visible").val(city);
	$("[id=manage_guest_country] option:contains(" +country+ ")").attr("selected","selected");
	var t2 = $("[id*=manage_guest_country]:last").val();
	print_state_bydom($("[id*=manage_guest_province]"),t2);
	$("[id=manage_guest_province]  option:contains(" +province+ ")").attr("selected","selected");
	$("[name=manage_guest_zipcode]:visible").val(zipcode);
	$("[name=manage_guest_tel]:visible").val(tel);
	$("[name=manage_guest_fax]:visible").val(fax);
	$("[name=manage_guest_email]:visible").val(email);

	$('[name=manage_guest_company_name]:visible').val(companyname);
	$('[name=manage_guest_company_address]:visible').val(companyaddress);
	$('[name=manage_guest_company_city]:visible').val(companycity);
	$('[id=manage_guest_company_country] option:contains(' +companycountry+ ')').attr('selected','selected');
	var t1 = $("[id*=manage_guest_company_country]:last").val();
	print_state_bydom($("[id*=manage_guest_company_province]"),t1);
	$('[id=manage_guest_company_province] option:contains(' +companyprovince+ ')').attr('selected','selected');
	$('[name=manage_guest_company_zipcode]:visible').val(companyzipcode);
	$('[name=manage_guest_company_tel]:visible').val(companytel);
	$('[name=manage_guest_company_fax]:visible').val(companyfax);
	$('[name=manage_guest_company_email]:visible').val(companyemail);
	
	$('[name=manage_guest_guestnote]').val(guestnote);
	$('[name=manage_guest_markvip]').attr('checked',markvip);
}


function AddEditGuestManage()
{ 
	var gid =0;
	if(getCurrentTabData().Owner!=null){
		( getCurrentTabData().Owner.id!= null)?gid=getCurrentTabData().Owner.id:0;	
	}
var data = { func : "EditGuestData",
		resId: getCurrentTabData().resId,
		SName:($("[name=manage_guest_salutation]:visible").val() !="-")?$("[name=manage_guest_salutation]:visible").find(':selected').val():0,
		Name:$("[name=manage_guest_name]:visible").val(),
		lastName:$("[name=manage_guest_lastname]:visible").val(),
	gender:($("[name=manage_guest_gender]:visible").val() !="-")?$("[name=manage_guest_gender]:visible").find(':selected').text():"",
	nationalityString:$("[name=manage_guest_nationality]:visible").val(),
	birthday:$("[name=manage_guest_dateborn_year]:visible").val()+"-"
			+$("[name=manage_guest_dateborn_month]:visible").val()+"-"
			+$("[name=manage_guest_dateborn_date]:visible").val(),
	idNumber:$("[name=manage_guest_idcard]:visible").val(),
	passportNumber:$("[name=manage_guest_passport]:visible").val(),
	driverlicense:$("[name=manage_guest_driverlicense]:visible").val(),
	socialSecuritycard:$("[name=manage_guest_socialsnumber]:visible").val(),
	addressLine:$("[name=manage_guest_address]:visible").val(),
	city:$("[name=manage_guest_city]:visible").val(),
	country:($("#manage_guest_country:visible").val() !="-")?$("[id=manage_guest_country]:visible").find(':selected').text():"",
	state:($("#manage_guest_province:visible").val() !="-")?$("[id=manage_guest_province]:visible").find(':selected').text():"",
	pincode:$("[name=manage_guest_zipcode]:visible").val(),
	phone:$("[name=manage_guest_tel]:visible").val(),
	fax:$("[name=manage_guest_fax]:visible").val(),
	mail:$("[name=manage_guest_email]:visible").val(),
	company:$('[name=manage_guest_company_name]:visible').val(),
	officeAddress:$('[name=manage_guest_company_address]:visible').val(),
	officeCity:$('[name=manage_guest_company_city]:visible').val(),
	officeCountry:($("#manage_guest_company_country:visible").val() !="-")?$("[id=manage_guest_company_country]:visible").find(':selected').text():"",
	officeState:($("#manage_guest_company_province:visible").val() !="-")?$("[id=manage_guest_company_province]:visible").find(':selected').text():"",
	officePincode:$('[name=manage_guest_company_zipcode]:visible').val(),
	officePhone:$('[name=manage_guest_company_tel]:visible').val(),
	officeFax:$('[name=manage_guest_company_fax]:visible').val(),
	officeEmail:$('[name=manage_guest_company_email]:visible').val(),
	isVIP:$('[name=manage_guest_markvip]:visible').is(":checked"),
	designation:$('[name=manage_guest_company_designation]:visible').val(),
	isBlackList:false,
	note:$('[name=manage_guest_guestnote]:visible')[0].value,
	guestId:gid
};
	var url = "/reservationService";
	simpleserviceWithArgs(url,data,load_addguest_success,gid);
}

function load_addguest_success(data,obj)
{
	var objArray = JSON.parse(data);
	var checkLogOut = CheckSession(objArray);
	if(checkLogOut)
		return;
	if(objArray  == null)
		simpleDialog(saveFail_label);
	else
	{
		var Tabs = getCurrentTabData();
		Tabs.Owner = objArray;
		fillOwnerInfo(Tabs);
		fillOwner(Tabs);
		editGuestChangeOwner(obj);
		LoadGuest(Tabs);
		if(Tabs.type!="Group"){
			Tabs.ResData.guestLastName=Tabs.Owner.lastName;
			Tabs.ResData.guestName=Tabs.Owner.firstName;
		}
	}
}

function editGuestChangeOwner(ownerId){
	Tabs=getCurrentTabData();
	var guestData=getObjectFromDataIndex(Tabs.guest,'id',ownerId);
	(guestData == null)?guestData ={}:"";
	guestData.Name=Tabs.Owner.firstName+" "+Tabs.Owner.lastName;
	var sName=getObjectFromSharedData(SharedData.Salutation,Tabs.Owner.salutationString)
	guestData.SName=(sName!=null)?sName.title:"";
	guestData.phone=Tabs.Owner.phone;
	guestData.mail=Tabs.Owner.mail;
	if(getObjectFromDataIndex(Tabs.guest,'id',ownerId)==null){
		(Tabs.guest == null)?Tabs.guest=[]:"";
		guestData.id=Tabs.Owner.id;
		Tabs.guest.push(guestData);
	}
}

function showManageResinGroupGuest(e)
{
	var dom = $(e).parents('tr [resid]');
		var buttons = [
		{ title:btn_add_guest , callback: function(thisdialog,args){
			addGuestResinGroup(dom)
			thisdialog.dialog("close");
		}},
		{ title:simpleLabel_Button_Close , callback: function(thisdialog,args){
			thisdialog.dialog("close");
		}}
	];
	var msgDialog = customDialog(Add_new_guest,$("[name=manage_guests_res_ingroup]").html(),{ width: 662},buttons,null);
	fillDropdown($("[name=manage_guest_salutation]"),SharedData.Salutation,"id","title");
	var Array  = JSON.parse('[{"gValue":"adult","gText":"adult"},{"gValue":"child","gText":"child"}]');
	fillDropdown($("[name=manage_guest_type]"),Array,"gValue","gText");
}

function addGuestResinGroup(dom)
{
	var resId = dom.attr('resid');
	var obj = {};
	obj.guestId = $('[name=res_ingroup_guest_guestid]:visible').attr('guestId');
		//dom.find('[name=edit_res_detail_guestname]').children().attr('guestid');
	($("[name=manage_guest_salutation]").val()=="-")?obj.salutation = 0:obj.salutation =$("[name=manage_guest_salutation]").val();
	obj.name = $("[name=res_ingroup_guest_name]:visible").val();
	obj.lastName =$("[name=res_ingroup_guest_lastname]:visible").val();
	obj.phone =$("[name=res_ingroup_guest_phone]:visible").val();
	var link = "/reservationService?func=InsertGuestResInGroup&resId="+resId+"&salutationId="+obj.salutation+"&name="+obj.name+"&lastName="+obj.lastName+"&phone="+obj.phone+"&guestId="+obj.guestId;
	simpleserviceWithArgs(link,null,addGuestResinGroupSuccess,dom);
}

function addGuestResinGroupSuccess(data,dom)
{
	var objArray =JSON.parse(data);
	var checkLogOut = CheckSession(objArray);
	if(checkLogOut)
		return;
	var Tabs = getCurrentTabData();
	if(objArray == null)
	{
		simpleDialog(saveFail_label);
	}else{
		dom.children()[4].innerHTML='<span guestid="'+objArray.id+'">'+objArray.Name+'</span><span class="brushimg" onclick="Clearguest(this)"></span>';
		dom.children()[5].innerHTML=objArray.phone;
		for(var i=0;i<Tabs.GroupResvList.length;i++){
			if(Tabs.GroupResvList[i].resId==objArray.resId)
				Tabs.GroupResvList[i].ResData.guestString = objArray.id;
		}
	}
}

function Clearguest(e)
{
	var dom =$(e).parents('tr [resid]');
	var resid =dom.attr('resid');
	var Tabs = getCurrentTabData();
	var StringArray="";
	for(var i= 0;i<Tabs.GroupResvList.length;i++)
	{
		if(Tabs.GroupResvList[i].ResData.id == parseInt(resid)){StringArray=Tabs.GroupResvList[i].ResData.guestString;}
	}
	var link = "/reservationService?func=removeGuestFormRes&resId="+resid+"&guestIdString="+StringArray;
	simpleserviceWithArgs(link,null,ClearguestSuccess,dom);
}
function ClearguestSuccess(data,dom)
{
	var Tabs = getCurrentTabData();
	var objArray =JSON.parse(data);
	if(objArray == null)
	{
		simpleDialog(saveFail_label);
	}else{
		dom.children()[4].innerHTML='<span guestid="0" class="link" onclick="showManageResinGroupGuest(this)">'+addGuest_label+'</span>';
		dom.children()[5].innerHTML="";
		for(var i=0;i<Tabs.GroupResvList.length;i++){
			if(Tabs.GroupResvList[i].resId==objArray.id)
				Tabs.GroupResvList[i].ResData.guestString ="0";
		}
	}
}